package com.workstudy.web.controller.workstudy;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.workstudy.common.annotation.Log;
import com.workstudy.common.enums.BusinessType;
import com.workstudy.workstudy.domain.WorkstudyAttendanceset;
import com.workstudy.workstudy.service.IWorkstudyAttendancesetService;
import com.workstudy.common.core.controller.BaseController;
import com.workstudy.common.core.domain.AjaxResult;
import com.workstudy.common.utils.poi.ExcelUtil;
import com.workstudy.common.core.page.TableDataInfo;

/**
 * 考勤设置Controller
 * 
 * @author ws
 * @date 2021-03-28
 */
@Controller
@RequestMapping("/workstudy/attendanceset")
public class WorkstudyAttendancesetController extends BaseController
{
    private String prefix = "workstudy/attendanceset";

    @Autowired
    private IWorkstudyAttendancesetService workstudyAttendancesetService;

    @RequiresPermissions("workstudy:attendanceset:view")
    @GetMapping()
    public String attendanceset(ModelMap mmap)
    {
        WorkstudyAttendanceset workstudyAttendanceset = workstudyAttendancesetService.selectWorkstudyAttendancesetById(1L);
        mmap.put("workstudyAttendanceset", workstudyAttendanceset);
        return prefix + "/edit";
    }

    /**
     * 查询考勤设置列表
     */
    @RequiresPermissions("workstudy:attendanceset:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WorkstudyAttendanceset workstudyAttendanceset)
    {
        startPage();
        List<WorkstudyAttendanceset> list = workstudyAttendancesetService.selectWorkstudyAttendancesetList(workstudyAttendanceset);
        return getDataTable(list);
    }

    /**
     * 导出考勤设置列表
     */
    @RequiresPermissions("workstudy:attendanceset:export")
    @Log(title = "考勤设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WorkstudyAttendanceset workstudyAttendanceset)
    {
        List<WorkstudyAttendanceset> list = workstudyAttendancesetService.selectWorkstudyAttendancesetList(workstudyAttendanceset);
        ExcelUtil<WorkstudyAttendanceset> util = new ExcelUtil<WorkstudyAttendanceset>(WorkstudyAttendanceset.class);
        return util.exportExcel(list, "attendanceset");
    }

    /**
     * 新增考勤设置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考勤设置
     */
    @RequiresPermissions("workstudy:attendanceset:add")
    @Log(title = "考勤设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WorkstudyAttendanceset workstudyAttendanceset)
    {
        return toAjax(workstudyAttendancesetService.insertWorkstudyAttendanceset(workstudyAttendanceset));
    }

    /**
     * 修改考勤设置
     */
    @GetMapping("/edit/{attendancesetId}")
    public String edit(@PathVariable("attendancesetId") Long attendancesetId, ModelMap mmap)
    {
        WorkstudyAttendanceset workstudyAttendanceset = workstudyAttendancesetService.selectWorkstudyAttendancesetById(attendancesetId);
        mmap.put("workstudyAttendanceset", workstudyAttendanceset);
        return prefix + "/edit";
    }

    /**
     * 修改保存考勤设置
     */
    @RequiresPermissions("workstudy:attendanceset:edit")
    @Log(title = "考勤设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WorkstudyAttendanceset workstudyAttendanceset)
    {
        return toAjax(workstudyAttendancesetService.updateWorkstudyAttendanceset(workstudyAttendanceset));
    }

    /**
     * 删除考勤设置
     */
    @RequiresPermissions("workstudy:attendanceset:remove")
    @Log(title = "考勤设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(workstudyAttendancesetService.deleteWorkstudyAttendancesetByIds(ids));
    }
}
